//
//  APPStoreVC.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2018/11/26.
//  Copyright © 2018年 Lssyyy. All rights reserved.
//

#import "APPStoreVC.h"
#import <StoreKit/StoreKit.h>
@interface APPStoreVC ()<SKStoreProductViewControllerDelegate>

@end

@implementation APPStoreVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //首先实例化一个VC
    SKStoreProductViewController *storeVC = [[SKStoreProductViewController alloc] init];
    //然后设置代理，注意这很重要，不如弹出就没法dismiss了
    storeVC.delegate = self;
    //接着弹出VC
    [storeVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@(493901993)} completionBlock:^(BOOL result, NSError * _Nullable error) {
        if (error) {
            NSLog(@"打开商店错误%@",error);
        }
    }];
    [self presentViewController:storeVC animated:YES completion:nil];
}
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
    //在代理方法里dismiss这个VC
    [viewController dismissViewControllerAnimated:YES completion:nil];
}
@end
